<template>
  <div>
    <div class="head-container">
      <el-form label-width="80px" size="small">
        <el-row type="flex">
          <el-col :xs="24" :sm="12" :md="8" :lg="12" :xl="12">
            <el-form-item label="客户名称">
              <el-input v-model="form.keyword" placeholder="输入客户名称搜索" />
            </el-form-item>
          </el-col>
          <el-col><el-button @click="query">搜索</el-button></el-col>
        </el-row>
      </el-form>
    </div>
    <el-table
      ref="customerTable"
      :data="customerList"
      style="width: 100%"
      max-height="250"
    >
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column  prop="code" label="编码" />
      <el-table-column  prop="name" label="名称" fixed="left" />
      <el-table-column  prop="type" label="客户类型">
        <template slot-scope="scope">
          {{ dict.label.t_bas_customer_type[scope.row.type] }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      layout="prev, pager, next"
      :total="pagination"
      :page-size="form.size"
      @current-change="upPagination"
      @size-change="upPagination"
    />
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="selectCustomer">确 定</el-button>
    </span>
  </div>
</template>

<script>
import { getCustomerList,getSCustomerList } from '@/api/erp/basCustomer'

export default {
  name: 'JCustomer',
  dicts: ['t_bas_customer_type'],
  props: {
    ctype: [String, Number],
    ids:{
      type:String,
      default:''
    }
  },
  data() {
    return {
      customerList: [],
      form: {
        page: 1,
        size: 10,
        type: null,
        keyword: null,
        sort: 'id,desc'
      },
      pagination: 0
    }
  },
  created() {
    this.form.type = this.ctype
    this.query()
  },
  methods: {
    query() {
      console.log(this.ctype)
      if (this.ctype === 3){
        getSCustomerList({...this.form,fCustomerIds:this.ids}).then(res=>{
          this.pagination = res.totalElements
          this.customerList = res.content
        })
        return
      }
      getCustomerList(this.form).then(res => {
        this.pagination = res.data.totalElements
        this.customerList = res.data.content
      })
    },
    upPagination(index) {
      this.form.page = index
      this.query()
    },
    selectCustomer() {
      const selectCustomerList = this.$refs.customerTable.selection
      this.$emit('selectCustomerList', selectCustomerList)
    }
  }
}
</script>

<style scoped>

</style>
